import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { NumInput } from "../common/NumInput";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GButton } from "../../../../com/mui/controls/GButton";
import { EOperOption } from "../../../../Message/Game/EOperOption";
import { QuickBuyWindow } from "../common/QuickBuyWindow";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ItemData } from "../../resource/info/ItemData";
import { GLabel } from "../../../../com/mui/controls/GLabel";
type int = number;
//class GuildContibuteWindow
    
    export  class GuildContibuteWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._tip = Language.getString(57011);
            this.init();
            return;
        }

        public init(): void
        {
            this.setSize(295, 290);
            this.titleHeight = 28;
            this.title = Language.getString(57012);
            ObjCreate.createBg(18, 42, 258, 100, this);
            ObjCreate.createTextField(Language.getString(57013), 30, 55, 220, 20, this);
            this._moneyInput = new NumInput();
            this._moneyInput.minNum = 5000;
            this._moneyInput.stepNumber = 500;
            this._moneyInput.x = 105;
            this._moneyInput.y = 55;
            this.addChild(this._moneyInput);
            ObjCreate.createTextField(Language.getString(57014), 30, 85, 220, 20, this);
            this._propInput = new NumInput();
            this._propInput.x = 105;
            this._propInput.y = 85;
            this.addChild(this._propInput);
            ObjCreate.createTextField(Language.getString(57393), 30, 115, 220, 20, this);
            this._goldInput = new NumInput();
            this._goldInput.x = 105;
            this._goldInput.y = 115;
            this.addChild(this._goldInput);
            this._contriMoneyBtn = ObjCreate.createGButton(Language.getString(57012), 195, 50, 49, 24, this);
            this._contriMoneyBtn.name = "contriMoneyBtn";
            this._contriMoneyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onContriBtnClickHandler);
            this._contriPropBtn = ObjCreate.createGButton(Language.getString(57012), 195, 80, 49, 24, this);
            this._contriPropBtn.name = "contriPropBtn";
            this._contriPropBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onContriBtnClickHandler);
            this._contriGoldBtn = ObjCreate.createGButton(Language.getString(57012), 195, 110, 49, 24, this);
            this._contriGoldBtn.name = "contriGoldBtn";
            this._contriGoldBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onContriBtnClickHandler);
            ObjCreate.createBg(18, 145, 258, 130, this);
            this._tipText = ObjCreate.createTextField("", 30, 155, 285, 20, this, GlobalStyle.textFormat2);
            this._tipText.htmlText = this._tip;
            this._tipText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            return;
        }

        public updateMaxAmount(arg1: int): void
        {
            var loc1=0;
            if (arg1 > 99) 
            {
                this._propInput.currentNum = 99;
                loc1 = 99;
            }
            else 
            {
                this._propInput.currentNum = arg1;
                loc1 = arg1;
            }
            this._propInput.maxNum = loc1;
            return;
        }

        public resetMaxAmount(): void
        {
            this._propInput.setMaxNum(this.getAddResItemNum());
            return;
        }

        /* internal  */onContriBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc1=arg1.target as GButton;
            if (loc1.name != "contriMoneyBtn") 
            {
                if (loc1.name != "contriGoldBtn") 
                {
                    loc2 = this._propInput.currentNum;
                    loc3 = EOperOption.convert(EOperOption._EOperOptionProp);
                    if ((loc6 = this.getAddResItemNum()) == 0) 
                    {
                        QuickBuyWindow.instance.updateWindow(ECategory._ECategoryProp, EProp._EPropGuildAddResource);
                        QuickBuyWindow.instance.show();
                        return;
                    }
                    if (loc2 > loc6) 
                    {
                        this._propInput.currentNum = loc6;
                        loc2 = loc6;
                    }
                }
                else 
                {
                    loc2 = this._goldInput.currentNum;
                    loc3 = EOperOption.convert(EOperOption._EOperOptionMoneyEx);
                    loc5 = Cache.instance.role.money.gold;
                    if (loc2 > loc5) 
                    {
                        this._goldInput.currentNum = loc5;
                        loc2 = this._goldInput.currentNum;
                    }
                    else 
                    {
                        this._goldInput.currentNum = loc2;
                        loc2 = this._goldInput.currentNum;
                    }
                }
            }
            else 
            {
                loc2 = this._moneyInput.currentNum;
                loc3 = EOperOption.convert(EOperOption._EOperOptionMoney);
                loc4 = Cache.instance.role.money.coin;
                if (loc2 > loc4) 
                {
                    this._moneyInput.currentNum = int(loc4 / 5000) * 5000;
                    loc2 = this._moneyInput.currentNum;
                }
                else 
                {
                    this._moneyInput.currentNum = int(loc2 / 5000) * 5000;
                    loc2 = this._moneyInput.currentNum;
                }
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDonateMoney, {"option": loc3, "num": loc2}));
            return;
        }

        /* internal  */getAddResItemNum(): int
        {
            var loc1=0;
            var loc2=Cache.instance.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropGuildAddResource);
            var loc3=0;
            while (loc3 < loc2.length) 
            {
                loc1 = loc1 + (loc2[loc3] as ItemData).itemAmount;
                ++loc3;
            }
            return loc1;
        }

        /* internal */ /* var */_titleLabel: GLabel;

        /* internal */ /* var */_tipText: Object /* flash.text.TextField */;

        /* internal */ /* var */_tip: string;

        /* internal */ /* var */_moneyInput: NumInput;

        /* internal */ /* var */_propInput: NumInput;

        /* internal */ /* var */_goldInput: NumInput;

        /* internal */ /* var */_contriMoneyBtn: GButton;

        /* internal */ /* var */_contriPropBtn: GButton;

        /* internal */ /* var */_contriGoldBtn: GButton;
    }
